package jafou.client.ui.objects;

import jafou.client.ui.ForumWidget;

import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.MenuItem;

public class ForumMenu extends MenuBar {
	private ForumWidget ui;
	
	private boolean createLoginItem = false;
	private MenuItem loginLogoutItem = null;
	
	public ForumMenu(ForumWidget ui, boolean createLoginItem) {
		this.ui = ui;
		this.createLoginItem = createLoginItem;
		setVisible(true);
		setup();
	}
	
	private void setup() {
		MenuItem forumItem = new MenuItem("forum", 
			new Command() {
				@Override
				public void execute() {
					Window.alert("not implemented yet!");
				}
			}
		);
		MenuItem topicItem = new MenuItem("topic", 
			new Command() {
				@Override
				public void execute() {
					Window.alert("not implemented yet!");
				}
			}
		);
		addItem(forumItem);
		addItem(topicItem);
		if("true".equals(ui.getUserAttribute("logged_in"))){
			MenuItem logoutItem = new MenuItem("logout", 
				new Command() {
					@Override
					public void execute() {
						Window.Location.assign(ui.getUserAttribute("logout_url"));
					}
				}
			);
			addItem(logoutItem);
		} else {
			MenuItem loginItem = new MenuItem("login", 
				new Command() {
					@Override
					public void execute() {
						Window.Location.assign(ui.getUserAttribute("login_url"));
					}
				}
			);
			addItem(loginItem);
		}
	}
	
}
